$(function(){
  /*禁用确认重新提交表单*/
  window.history.replaceState(null,null,window.location.href)
})

$("#banUpdateform").submit(function(e){
  /*禁用提交表单时刷新*/
  e.preventDefault();
})

/*判断是否登录*/
$(function(){
	if($("#logig_nameShow").text() == ""){
		$("#logig_nameShow").text("登录");
		window.location.href="login.jsp";
	}else{
		var message  = $("#logig_nameShow").text(); //获取 姓名
		$.ajax({
			url:"/12306/UserShowMessage.do?&message="+message,
			type:"POST",
			data:{
				"message":message
			},
			success:function(data){
					//console.log(data);
					/* 将身份证id某一段用*代替 */
					var idnum = data.user_id_num;
					var num = idnum.substring(0,4)+"***********"+idnum.substring(15,18);
					/* 将手机号某一段用*代替 */
					var pnum = data.user_phone;
					var pnums = pnum.substring(0,3)+"****"+pnum.substring(7,11);
					console.log(pnums)
					$("#complaintSuggestions_name").val(data.user_real_name);//真实姓名
					$("#complaintSuggestions_phone").val(pnums);//联系方式
					$("#complaintSuggestions_cardId").val(num);//身份证Id
					submitBut(idnum,pnum);
			}
		});
	}
})

//建议
function submitBut(idnum,pnum){
	$("#butSug_submit").click(function(){
		var username = $("input[name='userName_sug']").val();//姓名
		var userphone = pnum;//联系方式
		var userIdType = $("input[name='userIdType_sug']").val();//证件类型
		var userIdNum = idnum;//证件号
		var suggestionObject = $("select[name='suggestionObject']").val();//建议对象
		var suggestionText = $("textarea[name='suggestionText']").val();//建议内容
		$.ajax({
			url:"/12306/suggestions.do?&username="+username+"&userphone="+userphone+"&userIdType="+userIdType+"&userIdNum="+userIdNum+"&suggestionObject="+suggestionObject+"&suggestionText="+suggestionText,
			type:"POST",
			data:{
				"username":username,
				"userphone":userphone,
				"userIdType":userIdType,
				"userIdNum":userIdNum,
				"suggestionObject":suggestionObject,
				"suggestionText":suggestionText
			},
			success:function(data){
				console.log(data);
			}
		});
	})
}


/* 爱心模式 */
var num = 0;
$("#heart_schema").click(function() {
  if( num == 0){
     $("#heart").show(1).slideDown(1).fadeIn();
     /*获取滚动条高度*/
     $(window).scroll(function(){
        if($(window).scrollTop()>=100){
          $("#heart").css("z-index","1000");
          $("#heart").css({"position":"fixed","top":"0px"});
        }else{
          $("#heart").css("position","relative");
        }
     })
     num=1;
  }else if(num==1){
    $("#heart").hide(500).slideUp(500).fadeOut();
    num = 0;
  }
})

/*退出爱心模式*/
$("#heart_exit").click(function() {
  $("#heart").hide(500).slideUp(500).fadeOut();
})

/* 修改heart_point 下img标签中src图片路径 */
$("#heart_point").click(function() {
  $("#heart_point").find("img").css("content","url(images/continuous_stop1.png)");
})

// 搜索按钮
$("#search—bon").mouseover(function(){
  $("#search—bon").css("backgroundColor","blue");
})
$("#search—bon").mouseout(function(){
  $("#search—bon").css("backgroundColor","#3B99FC");
})

/* 实现English下拉单  显示*/
$("#Englishs").mouseenter(function(){
  $("#EnglishSlide").show(1).slideDown(1).fadeIn();

})

$("#Englishs").mouseleave(function(){
  $("#EnglishSlide").hide(1).slideUp(1).fadeOut();
})


/* 实现我的12306下拉单  显示*/
$("#myslide").mouseenter(function(){
  $("#my12306").show(1).slideDown(1).fadeIn();
})

$("#myslide").mouseleave(function(){
  $("#my12306").hide(1).slideUp(1).fadeOut();
})


/* 实现导航条中的效果*/
$(".n_arrow").parents("li").mouseover(function(){
  $(this).find($(".n_arrow")).css("animation","boxIn 0.5s  ease-in forwards");
  $(this).css("backgroundColor","#2676E3");
})

$(".n_arrow").parents("li").mouseout(function(){
  $(this).find($(".n_arrow")).css("animation","boxout 0.5s  ease-in forwards");
  $(this).css("backgroundColor","#3B99FC")
})

/* 实现导航条中的下拉列表*/
/*导航条>车票*/
$("#n_arrow_ticket").mouseenter(function(){
  $(".navigation").hide(10).slideUp(10).fadeOut();
  $("#ticket").show(10).slideDown(10).fadeIn();
})

$("#n_arrow_ticket").mouseleave(function(){
  $("#ticket").hide(10).slideUp(10).fadeOut();
})

/*导航条>团购服务*/
$("#n_arrow_team").mouseenter(function(){
  $(".navigation").hide(10).slideUp(10).fadeOut();
  $("#team").show(10).slideDown(10).fadeIn();
})

$("#n_arrow_team").mouseleave(function(){
  $("#team").hide(10).slideUp(10).fadeOut();
})

/*导航条>会员服务*/
$("#n_arrow_vipServe").mouseenter(function(){
  $(".navigation").hide(10).slideUp(10).fadeOut();
  $("#vipServe").show(10).slideDown(10).fadeIn();
})

$("#n_arrow_vipServe").mouseleave(function(){
  $("#vipServe").hide(10).slideUp(10).fadeOut();
})

/*导航条>站车服务*/
$("#n_arrow_station").mouseenter(function(){
  $(".navigation").hide(10).slideUp(10).fadeOut();
  $("#station").show(10).slideDown(10).fadeIn();
})

$("#n_arrow_station").mouseleave(function(){
  $("#station").hide(10).slideUp(10).fadeOut();
})

/*导航条>商旅服务*/
$("#n_arrow_tour").mouseenter(function(){
  $(".navigation").hide(10).slideUp(10).fadeOut();
  $("#tour").show(10).slideDown(10).fadeIn();
})

$("#n_arrow_tour").mouseleave(function(){
  $("#tour").hide(10).slideUp(10).fadeOut();
})

/*导航条>出行指南*/
$("#n_arrow_trip").mouseenter(function(){
  $(".navigation").hide(10).slideUp(10).fadeOut();
  $("#trip").show(10).slideDown(10).fadeIn();
})

$("#n_arrow_trip").mouseleave(function(){
  $("#trip").hide(10).slideUp(10).fadeOut();
})

/*导航条>信用信息*/
$("#n_arrow_message").mouseenter(function(){
  $(".navigation").hide(10).slideUp(10).fadeOut();
  $("#message").show(10).slideDown(10).fadeIn();
})

$("#n_arrow_message").mouseleave(function(){
  $("#message").hide(10).slideUp(10).fadeOut();
})

/*左侧导航*/
var midNum = 0;
/*订单中心*/
$("#cent_mid_indent").click(function(){
  if(midNum == 0){
    $("#mid_indent").hide();
    midNum = 1;
  }else{
    $("#mid_indent").show();
    midNum = 0;
  }
  
})

/*个人信息*/
$("#cent_mid_myMess").click(function(){
  if( midNum == 0){
    $("#mid_myMess").hide();
     midNum = 1;
  }else{
    $("#mid_myMess").show();
     midNum = 0;
  }
  
})

/*常用信息管理*/
$("#cent_mid_adminMess").click(function(){
  if(midNum == 0){
    $("#mid_adminMess").hide();
    midNum = 1;
  }else{
    $("#mid_adminMess").show();
    midNum = 0;
  }
})

/*温馨服务*/
$("#cent_mid_serve").click(function(){
  if(midNum == 0){
    $("#mid_serve").hide();
    midNum = 1;
  }else{
    $("#mid_serve").show();
    midNum = 0;
  }
  
})

/*投诉和建议*/
$("#cent_mid_complain").click(function(){
  if(midNum == 0){
    $("#mid_complain").hide();
    midNum = 1;
  }else{
    $("#mid_complain").show();
    midNum = 0;
  }
})


/*个人中心*/
function showTime(){
    var today=new Date();//创建日期对象
    var myHou1=today.getHours();//获取时间 hour
    if(myHou1 >= 6 && myHou1 <= 12){//6:00-12：00
      $("#mid_indent_time").text("上午好！");
    }

    if(myHou1 >= 13 && myHou1 <= 18){//13:00-18：00
      $("#mid_indent_time").text("下午好！");
    }

    if((myHou1 >= 19 && myHou1 <= 23) || (myHou1 >= 0 && myHou1 <= 5)){//18:00-5：00（次日）
      $("#mid_indent_time").text("晚上好！");
    }
  };
  setInterval("showTime()", 1);

/*订单中心*/
/*获取日期并转换成相应格式*/
var now = new Date();
var year = now.getFullYear();
/*month返回数组（0-11）*/
var month = ("0" + (now.getMonth() + 1)).slice(-2);
/*getDate返回日期(1-31)*/
var day = ("0" + now.getDate()).slice(-2);
/*年月日*/
var formatedDate = year + "-" + month + "-" + day;
/*月日*/
var formatedDate1 = month + "-" + day;
/*设置class类类名是now_date的日期*/
$(".now_date").val(formatedDate);


/*个人中心*/
$("#indent_one").click(function(){
  $(".cent_mid_right_alls").hide();
  $("#mid_right_indent").show();
  $("#indent_ticket_menu").css("backgroundColor","white");
  $("#indent_ticket_menu").css("color","gray");
})

/*订单中心>火车票订单*/
$("#indent_ticket_menu").click(function(){
  $(".cent_mid_right_alls").hide();
  $("#mid_right_indent_ticket").show();
  $(this).css("backgroundColor","#3B99FC");
  $(this).css("color","white");
})

/*其他功能*/
$(".orthers_fun").click(function(){
  $(".cent_mid_right_alls").hide();
  $("#others_indent").show();
})

/*本人车票*/
$("#mid_myTicket").click(function(){
  $(".cent_mid_right_alls").hide();
  $("#mid_myTicket_show").show();
})

/*个人信息>查看个人信息*/
$("#mid_myOne").click(function(){
  $(".cent_mid_right_alls").hide();
  $("#mid_myOne_ms").show();
  var message  = $("#logig_nameShow").text(); //获取 姓名
  $.ajax({
	url:"/12306/UserShowMessage.do?&message="+message,
	type:"POST",
	data:{
		"message":message
	},
	success:function(data){
			console.log(data);
			$("#basicInformation_username").text(data.user_name);//用户名
			$("#basicInformation_userrealname").text(data.user_real_name);//真实姓名
			/* 将身份证id某一段用*代替 */
			var idnum = data.user_id_num;
			var num = idnum.substring(0,4)+"***********"+idnum.substring(15,18);
			$("#basicInformation_userIdNum").text(num);//身份证号
			var pnum = data.user_phone;
			var pnums = pnum.substring(0,3)+"****"+pnum.substring(7,11);
			$("#contactDetails_phone").text(pnums);//手机号
				
	}
  });
})

/*联系方式*/
$("#but_contactDetails").click(function(){
  $("#contactDetails_show").find("input").css("border","2px solid lightgrey");
  $("#contactDetails_show").find("input").removeAttr("disabled");
})

/*附加信息*/
$("#but_additional").click(function(){
  $("#additional_Information_show").find("select").css("border","2px solid lightgrey");
  $("#additional_Information_show").find("select").removeAttr("disabled");
})

/*个人信息>账号安全*/
$("#mid_accountSecurity").click(function(){
  $(".cent_mid_right_alls").hide();
  $("#accountSecurity").show();
})

/*个人信息>账号安全>登陆密码*/
$("#accountSecurity_updatePassword").click(function(){
	$("#accountSecurity").find("#accountSecurity_start").hide();
	$("#accountSecurity_loginPassword").show();
	var message  = $("#logig_nameShow").text(); //获取姓名
	  $.ajax({
		url:"/12306/UserShowMessage.do?&message="+message,
		type:"POST",
		data:{
			"message":message
		},
		success:function(data){
			console.log(data)
			updatePassword(data);
		}
	  });
})
/*将新密码提交后台并判断*/
function updatePassword(data){
	$("#loginPassword_button").click(function(){
		var username = data.user_name;//用户名
		var oldPassword = $("input[name='loginPassword_old']").val();//原密码
		var newPassword = $("input[name='loginPassword_new']").val();//新密码
		var newSurePassword = $("input[name='loginPassword_new_sure']").val();//新密码确认
		$.ajax({
			url:"/12306/UpdatePassword.do?&username="+username+"&oldPassword="+oldPassword+"&newPassword="+newPassword+"&newSurePassword="+newSurePassword,
			type:"POST",
			data:{
				"username":username,
				"oldPassword":oldPassword,
				"newPassword":newPassword,
				"newSurePassword":newSurePassword
			},
			success:function(data){
				if(data == 0){
					$("#loginPassword_ms_show").text("密码错误，修改失败");
				}else if(data == 1){
					$("#loginPassword_ms_show").text("修改成功");
				}else{
					$("#loginPassword_ms_show").text("密码不能为空或新密码确认失败，修改失败");
				}
			}
		});
	})
}


/*个人信息>账号安全>手机核验*/
$("#accountSecurity_updatePhone").click(function(){
  $(".cent_mid_right_alls").hide();
  $("#mid_phoneVerification_M").show();
  showPhone();
})

/*个人信息>账号安全>安全邮箱*/
$("#accountSecurity_updateEmail").click(function(){
	$("#accountSecurity").find("#accountSecurity_start").hide();
	$("#accountSecurity_email").show();
	var message  = $("#logig_nameShow").text(); //获取姓名
	  $.ajax({
		url:"/12306/UserShowMessage.do?&message="+message,
		type:"POST",
		data:{
			"message":message
		},
		success:function(data){
			console.log(data)
			$("#accountSecurity_emailOld").text(data.user_email);
			updateEmail(data);
		}
	  });
})

/*将新Email提交后台并判断*/
function updateEmail(data){
	$("#accountSecurity_emailButton").click(function(){
		var username = data.user_name;
		var emailNew = $("input[name='accountSecurity_emailNew']").val();//新电子邮件
		var passwordEmail = $("input[name='email_password']").val();//登陆密码
		$.ajax({
			url:"/12306/UpadateEmail.do?&username="+username+"&emailNew="+emailNew+"&passwordEmail="+passwordEmail,
			type:"POST",
			data:{
				"username":username,
				"emailNew":emailNew,
				"passwordEmail":passwordEmail
			},
			success:function(data){
				console.log(data+"datas")
				if(data == 0){
					$("#email_ms_show").text("密码错误，修改失败");
				}else if(data == 1){
					$("#email_ms_show").text("修改成功");
				}else{
					$("#email_ms_show").text("电子邮箱或密码不能为空，修改失败");
				}
			}
		})
	})
}

/*个人信息>账号安全>通知设置*/
$("#accountSecurity_notice").click(function(){
  $(".cent_mid_right_alls").hide();
	$("#others_indent").show();
})

/*个人信息>手机核验*/
$("#mid_phoneVerification").click(function(){
  $(".cent_mid_right_alls").hide();
  $("#mid_phoneVerification_M").show();
  showPhone();
  
})

function showPhone(){
	 var message  = $("#logig_nameShow").text(); //获取姓名
	  $.ajax({
		url:"/12306/UserShowMessage.do?&message="+message,
		type:"POST",
		data:{
			"message":message
		},
		success:function(data){
			console.log(data)
			var pnum = data.user_phone;
			var pnums = pnum.substring(0,3)+"****"+pnum.substring(7,11);
			$("#mid_phoneVerification_oldPhone").text(pnums);//手机号
			surePhoneVerification(data);
		}
	  });
}

/*手机核验数据传入后台*/
function surePhoneVerification(data){
	$("#phoneVerification_sure").click(function(){
		var newphone = $("input[name='mid_phoneVerification_newPhone']").val();//新手机号
		var password = $("input[name='mid_phoneVerification_password']").val();//登录密码
		var username = data.user_name;
		var reg = /(1[3-9]\d{9}$)/;
		if (!reg.test(newphone)){
	         $("#mid_phoneVerification_ms").text("请输入正确格式的手机号码！")
	         return;
		}
		$.ajax({
			url:"/12306/MobilePhoneVerification.do?&newphone="+newphone+"&password="+password+"&username="+username,
			type:"POST",
			data:{
				"username":username,
				"newphone":newphone,
				"password":password
			},
			success:function(data){
				if(data == 0){
					$("#mid_phoneVerification_ms").text("密码错误，修改失败");
				}else if(data == 1){
					$("#mid_phoneVerification_ms").text("修改成功");
				}else{
					$("#mid_phoneVerification_ms").text("手机号或密码不能为空，修改失败");
				}
			}
		})
	})
}


/*个人信息>账号注销*/
$("#mid_accountCancellation").click(function(){
  $(".cent_mid_right_alls").hide();
  $("#accountCancellation").show();
})

/*投诉和建议>建议*/
$("#mid_complaintSuggestions_s").click(function(){
  $(".cent_mid_right_alls").hide();
  $("#complaintSuggestions_s").show();
})

$("#reload_refund").click(function(){
  location.reload(true);
})

$("#agreeToread").click(function(){
  $("#complaintSuggestions_s_start").hide();
  $("#complaintSuggestions_s_show").show();
})